-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix asset route caching #1002
base: main
Are you sure you want to change the base?
Fix asset route caching #1002
Conversation
@vorban thanks for the PR! I made a couple of small changes but all looks good to me. The scenarioCurrently, if you run The problemWhat is happening is that Flux's asset routes are currently registered using closures. For example: Route::get('/flux/flux.css', function () {
return Flux::pro()
? $this->pretendResponseIsFile(__DIR__.'/../../flux-pro/dist/flux.css', 'text/css')
: $this->pretendResponseIsFile(__DIR__.'/../../flux/dist/flux-lite.css', 'text/css');
}); So when these closures are serialised, PHP actually converts the 'generated::BgAuGLqPz9H8AUEs' =>
array (
...
'uri' => 'flux/flux.css',
'action' =>
array (
'uses' => 'O:55:"Laravel\\SerializableClosure\\UnsignedSerializableClosure":1:{s:12:"serializable";O:46:"Laravel\\SerializableClosure\\Serializers\\Native":5:{s:3:"use";a:0:{}s:8:"function";s:334:"function () {
return \\Flux\\Flux::pro()
? $this->pretendResponseIsFile(\'/Users/josh/Development/packages/flux/src\'.\'/../../flux-pro/dist/flux.css\', \'text/css\')
: $this->pretendResponseIsFile(\'/Users/josh/Development/packages/flux/src\'.\'/../../flux/dist/flux-lite.css\', \'text/css\');
}";s:5:"scope";s:17:"Flux\\AssetManager";s:4:"this";O:17:"Flux\\AssetManager":0:{}s:4:"self";s:32:"00000000000004670000000000000000";}}',
'as' => 'generated::BgAuGLqPz9H8AUEs',
),
'...
), As you can see above, the path from my local machine The solutionThe solution submitted by @vorban is to remove the closures and actually make methods on the Route::get('/flux/flux.css', [static::class, 'fluxCss']);
...
public function fluxCss() {
return Flux::pro()
? $this->pretendResponseIsFile(__DIR__.'/../../flux-pro/dist/flux.css', 'text/css')
: $this->pretendResponseIsFile(__DIR__.'/../../flux/dist/flux-lite.css', 'text/css');
} By doing this, the compile route now looks like this. 'generated::NsQPI42I75o5heuR' =>
array (
...
'uri' => 'flux/flux.css',
'action' =>
array (
'uses' => 'Flux\\AssetManager@fluxCss',
'controller' => 'Flux\\AssetManager@fluxCss',
'as' => 'generated::NsQPI42I75o5heuR',
),
...
), Now we can see that the route references the Fixes #998 |
This addresses #998 .
Before:
php artisan route:cache
serializes through reflection the route callbacks, hardwiring the execution context's absolute path to flux's asset files (ex: /Users/vorban/repositories/...) because of__DIR__
resolution.After:
php artisan route:cache
serializes references to the route actions, preventing any resolution of__DIR__
before runtime.I've tested it locally. The routes are listed by
artisan route:list
, andartisan route:cache
correctly serialized references to the functions.After a
route:cache
, going to any page that uses the blade directives like@fluxStyles
works and the files are correctly fetched.I'd prefer this to be thoroughly reviewed, as I failed to find the contribution guidelines and test suites to run.